package org.yefei.homeworkday16.carrentsysem;

public class CarCompany {
	private String name;// 公司名称
	private int tele;// 公司电话
	Car[] car = { new Limousine("别克英朗", "京A001", 400, true, 5, "轿车"),
			new Limousine("吉利-宋", "京A002", 400, true, 5, "轿车"), new Limousine("吉利-唐", "京A003", 500, true, 5, "轿车"),
			new Coach("金龙大客", "京A004", 900, true, 16, "客车"), new Coach("江淮客车", "京A005", 950, true, 20, "客车"), null,
			null, null, null, null, null };// 车位信息

	public CarCompany() {
	}

	public CarCompany(String name, int tele) {
		this.name = name;
		this.tele = tele;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getTele() {
		return tele;
	}

	public void setTele(int tele) {
		this.tele = tele;
	}

//公司信息
	public void showCom() {
		System.out.println(name + "欢迎您，请致电" + tele + "洽谈相关租赁业务");

	}

//查看车辆情况
	public void showInfo() {
		System.out.println("本公司现有以下车辆可租：");
		System.out.println("品牌\t车牌号\t\t日租金（元）\t状态\t座位数\t类型");
		for (int i = 0; i < car.length; i++) {
			if (car[i] != null) {
				car[i].showCar();
			}

		}
	}

	// 租赁-显示租赁不同类型的车信息
	public void showLeaseObj(String t) {
		if ((t.equals("客车")) || t.equals("轿车")) {
			System.out.println("可选的车辆信息如下：");
			System.out.println("品牌\t车牌号\t\t日租金（元）\t状态\t座位数\t类型");
			for (int i = 0; i < car.length && car[i] != null; i++) {
				if (t.equals("客车")) {
					if (car[i] instanceof Coach) {
						car[i].showCar();
					}
				} else if (t.equals("轿车")) {
					if (car[i] instanceof Limousine) {
						car[i].showCar();
					}
				}
			}
		} else {
			System.out.println("输入错误！");
			return;
		}
	}

	int j = 0;

// 租赁-根据车牌号选择租的车
	public boolean chooseCnum(String n) {
		for (int i = 0; i < car.length; i++) {
			if (car[i] != null && car[i].getState() == true && n.equals(car[i].getcNum())) {
				System.out.println("您选择租的车辆信息如下：");
				car[i].showCar();
				j = i;
				return true;
			}
		}
		return false;
	}

//租赁-给钱拿车
	public Car getCar(int d) {
		if (car[j].getState() == true) {
			double calDateRent = car[j].calDateRent(d);
			System.out.println("您需要支付的金为：" + calDateRent);
			System.out.println(car[j]);
			car[j].setState(false);
			return car[j];
		}
		return null;
	}

	// 还车
	public boolean reback(String m) {
		for (int i = 0; i < car.length; i++) {
			if (car[i] != null && car[i].getState() == false && m.equals(car[i].getcNum())) {
				car[i].setState(true);
				System.out.println("还车成功");
				return true;
			}
		}
		return false;
	}

	// 报废
	public boolean scrap(String num) {
		for (int i = 0; i < car.length; i++) {
			if (car[i] != null && car[i].getState() == true && (car[i].getcNum()).equals(num)) {
				for (int j = i + 1; j < car.length; j++) {
					car[j - 1] = car[j];
				}
				car[car.length - 1] = null;
				System.out.println("车量报废成功！");
				return true;
			}
		}
		return false;
	}

	// 新增车辆
	public boolean addCar(Car c) {
		for (int i = 0; i < car.length; i++) {
			if (car[i] == null && c instanceof Coach) {
				car[i] = c;
				c.showCar();
				System.out.println("客车添加成功！");
				break;
			} else if (car[i] == null && c instanceof Limousine) {
				car[i] = c;
				c.showCar();
				System.out.println("货车添加成功");
				break;
			}
		}
		return false;

	}

}
